package test;

import java.util.Collection;
import java.util.Scanner;

class ArrayUtils{
	public static double findMax(double[] arr,int begin, int end)throws IllegalArgumentException{
		if(begin>=end)
			throw new IllegalArgumentException("begin:"+begin+">="+"end:"+end);
		if(begin<0)
			throw new IllegalArgumentException("begin:"+begin+"<0");
		if(end>arr.length)
			throw new IllegalArgumentException("end:"+end+" > arr.length");
		else{
		int x=begin;
		double max=arr[x];
		for(;x>=begin&&x<=end-2;x++){
			if(arr[x]<arr[x+1])
				max=arr[x+1];
		}
			
			
			
		
		return max;
		}
	}


}
public class Main3 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int num=sc.nextInt();
		double[]str=new double[num];
		for(int a=0;a<num;a++){
			double p=sc.nextDouble();
			str[a]=p;
		}
		while(sc.hasNext()){
			String c=sc.next();
			String d=sc.next();
			int k=Integer.valueOf(c);
			int g=Integer.valueOf(d);
			if(k>9&&k<0&&g>9&&g<0)
				break;
			else{
				
				System.out.println(ArrayUtils.findMax(str, k, g));
			}
		}
		try {
		     System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class,int.class,int.class));
		} catch (Exception e1) {
		}
	}
}

